use serde::{Deserialize, Serialize};
use ts_rs::TS;

use super::IndicatorActionWrap;

///
/// Parabolic Stop And Reverse
///
/// 参见[SAR](https://docs.rs/yata/latest/yata/indicators/struct.ParabolicSAR.html)
///
#[derive(Debug, Serialize, Deserialize, Default, TS, Clone)]
#[ts(export)]
pub struct SAR {
    /// 1 signal
    /// When trend changes it’s value to positive, then returns full buy signal.
    /// When trend changes it’s value to negative, then returns full sell signal.
    /// Otherwise returns no signal.
    pub signal0: Option<IndicatorActionWrap>,
    /// SAR value
    /// Range of values is the same as the range of the timeseries values.
    pub sar: f64,

    /// trend value
    /// Can be one of the next values: {-1.0; 0.0; 1.0}
    pub trend: f64,
}

/// Configuration for the Parabolic Stop And Reverse SAR indicator.
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct SARConfig {
    pub af_step: f64,
    pub af_max: f64,
}

impl Default for SARConfig {
    fn default() -> Self {
        SARConfig {
            af_step: 0.02,
            af_max: 0.2,
        }
    }
}
